

import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:provider/provider.dart';
import 'package:ysy_flutter_mvvm_yuanxuan/bean/mine/MineBean.dart';
import 'package:ysy_flutter_mvvm_yuanxuan/helper/ImageHelper.dart';
import 'package:ysy_flutter_mvvm_yuanxuan/helper/RouteHelper.dart';
import 'package:ysy_flutter_mvvm_yuanxuan/helper/ViewHelper.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:ysy_flutter_mvvm_yuanxuan/view/main/mine/MineVM.dart';

//工作台
class WorkbenchWidget extends StatefulWidget{

  MineVM mineVM;
  WorkbenchWidget(this.mineVM);

  @override
  _WorkbenchWidgetState createState() => _WorkbenchWidgetState();
}

class _WorkbenchWidgetState extends State<WorkbenchWidget>  with AutomaticKeepAliveClientMixin{
  @override
  Widget build(BuildContext context) {
    return Container(
      padding: EdgeInsets.fromLTRB(0, 20.h, 0, 0),
      child: ChangeNotifierProvider(
        create: (BuildContext context) {
          return widget.mineVM;
        },
        child: Selector(
          selector: (BuildContext ,MineVM mineVM ) {
            return mineVM.mineBean;
          },
          builder: (BuildContext context,MineBean? value, Widget? child) {
            return Column(
              children: [
                Container(
                  height: 116.h,
                  width: double.infinity,
                  padding: EdgeInsets.all(12.h),
                  decoration:BoxDecoration(
                      color: Colors.white,
                      borderRadius:BorderRadius.all(Radius.circular(12.r))
                  ) ,
                  child: Column(
                    children: [
                      Row(
                        crossAxisAlignment: CrossAxisAlignment.center,
                        children: [
                          Text("我的订单",style: TextStyle(fontWeight: FontWeight.w700,color: Colors.black,fontSize: 15.sp)),
                          Expanded(child: Text("全部订单",textAlign: TextAlign.right,style: TextStyle(color: Color(0xff999999),fontSize: 12.sp))),
                          Padding(padding: EdgeInsets.fromLTRB(8, 0, 0, 0)),
                          Image.asset(assetPath("ic_order_right_arrow.png"),height: 10.h,fit: BoxFit.fitHeight,)
                        ],
                      ),
                      Expanded(
                        child: Container(
                          alignment: Alignment.center,
                          margin: EdgeInsets.fromLTRB(0, 10.h, 0, 0),
                          child: Row(
                            mainAxisAlignment: MainAxisAlignment.spaceBetween,
                            crossAxisAlignment: CrossAxisAlignment.center,
                            children: [
                              InkWell(onTap: (){
                                 toOrderWidget(context);
                              },child: OrderFun(name: "待付款",ic:"ic_my_order_dfk.png",num: value?.orderCategoryCounts?[0].count??0)),
                              InkWell(onTap: (){
                                toOrderWidget(context);
                              },child: OrderFun(name:"待发货",ic:"ic_my_order_dfh.png",num: value?.orderCategoryCounts?[1].count??0)),
                              InkWell(onTap: (){
                                toOrderWidget(context);
                              },child: OrderFun(name:"待收货",ic:"ic_my_order_dsh.png",num: value?.orderCategoryCounts?[2].count??0)),
                              InkWell(onTap: (){
                                toOrderWidget(context);
                              },child: OrderFun(name:"待评价",ic:"ic_my_order_dpj.png",num: value?.orderCategoryCounts?[3].count??0)),
                              OrderFun(name:"售后/退款",ic:"ic_my_order_tksh.png",num: value?.orderCategoryCounts?[4].count??0),
                            ],),
                        ),
                      ),
                    ],
                  ),
                ),
                InkWell(onTap: (){
                   showCenterToast("你没有权限查看");
                },child: MyFun("商品收藏", "ic_my_collection.png", "${value?.productCollect??0}")),
                InkWell(onTap: (){
                  showCenterToast("你没有权限查看");
                },child: MyFun("关注店铺", "ic_my_follow_store.png", "${value?.storeCollect??0}")),
                InkWell(onTap: (){
                  showCenterToast("你没有权限查看");
                },child: MyFun("喜欢的内容", "ic_my_favorite_content.png", "${value?.favoriteContent??0}")),
                InkWell(onTap: (){
                  showCenterToast("你没有权限查看");
                }, child: MyFun("浏览记录", "ic_my_browsing_history.png", "${value?.browsingRecords??0}")),
              ],
            );
          },
        ),
      ),
    );
  }

  @override
  bool get wantKeepAlive => true;
}



class OrderFun extends StatelessWidget {

  String name;
  String ic;
  int num;

  OrderFun({required this.name,required this.ic,required this.num});

  @override
  Widget build(BuildContext context) {
    return Column(
      crossAxisAlignment: CrossAxisAlignment.center,
      mainAxisAlignment: MainAxisAlignment.center,
      children: [
        RightTag(valueNotifier: ValueNotifier(num),
            child: Image.asset(assetPath(ic),height: 20.h,fit: BoxFit.fitHeight)),
        Padding(padding: EdgeInsets.fromLTRB(0, 12.h, 0, 0)),
        Text("${name}",style: TextStyle(fontSize: 13.sp,color: Colors.black),)
      ],
    );
  }
}


class MyFun extends StatelessWidget {

  String name;
  String ic;
  String num;

  MyFun(this.name, this.ic, this.num);

  @override
  Widget build(BuildContext context) {
    return Container(
      margin: EdgeInsets.fromLTRB(0, 12.h, 0, 0),
      padding: EdgeInsets.fromLTRB(12.w, 0, 12.w, 0),
      decoration:BoxDecoration(
          color: Colors.white,
          borderRadius:BorderRadius.all(Radius.circular(12.r))
      ),
      height: 65.h,
       child: Row(
          crossAxisAlignment: CrossAxisAlignment.center,
          children: [
            Image.asset(assetPath(ic),width: 18.sp,height: 18.sp,fit: BoxFit.fill,),
            Padding(padding: EdgeInsets.fromLTRB(0, 0, 12.w, 0)),
            Expanded(child: Text(name,style: TextStyle(color: Colors.black,fontSize: 15.sp),)),
            Text("${num}",style: TextStyle(color: Colors.black,fontSize: 15.sp)),
            Padding(padding: EdgeInsets.fromLTRB(0, 0, 8.w, 0)),
            Image.asset(assetPath("ic_order_right_arrow.png"),height: 10.h,fit: BoxFit.fitHeight,)
          ],
       ),
    );
  }
}

